//
//  WHCoopInfoCell.m
//  SquirrelCourier
//
//  Created by 邓伟浩 on 2019/1/4.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHCoopInfoCell.h"

@interface WHCoopInfoCell ()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UIButton *editBtn;

@end

@implementation WHCoopInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = CViewBgMainColor;
        [self setMoneyDetailInfoUI];
    }
    return self;
}

- (void)setMoneyDetailInfoUI {
    [self.contentView addSubview:({
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.adjustsFontSizeToFitWidth = YES;
        _nameLabel.textColor = CFontContentGrayColor;
        _nameLabel.font = SYSTEMFONT(kRealwidth(15));
        
        ViewBorderRadius(_nameLabel, 0, 0.5, CLineColor);
        
        _nameLabel;
    })];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.mas_equalTo(self.contentView);
        make.width.mas_equalTo(kRealwidth(130));
    }];
    
    [self.contentView addSubview:({
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.textAlignment = NSTextAlignmentCenter;
        _moneyLabel.adjustsFontSizeToFitWidth = YES;
        _moneyLabel.textColor = CFontContentGrayColor;
        _moneyLabel.font = SYSTEMFONT(kRealwidth(15));
        
        ViewBorderRadius(_moneyLabel, 0, 0.5, CLineColor);
        
        _moneyLabel;
    })];
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.contentView);
        make.left.mas_equalTo(_nameLabel.mas_right);
        make.width.mas_equalTo(kRealwidth(115));
    }];
    
    [self.contentView addSubview:({
        _statusLabel = [[UILabel alloc] init];
        _statusLabel.textAlignment = NSTextAlignmentCenter;
        _statusLabel.adjustsFontSizeToFitWidth = YES;
        _statusLabel.textColor = CFontContentGrayColor;
        _statusLabel.font = SYSTEMFONT(kRealwidth(15));
        
        ViewBorderRadius(_statusLabel, 0, 0.5, CLineColor);
        
        _statusLabel;
    })];
    [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.contentView);
        make.left.mas_equalTo(_moneyLabel.mas_right);
        make.width.mas_equalTo(kRealwidth(65));
    }];
    
    [self.contentView addSubview:({
        _editBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        _editBtn.titleLabel.font = SYSTEMFONT(kRealwidth(15));
        [_editBtn setTitleColor:CMDarkOrangeColor forState:UIControlStateNormal];
        
        ViewBorderRadius(_editBtn, 0, 0.5, CLineColor);
        [_editBtn addTarget:self action:@selector(edit:) forControlEvents:UIControlEventTouchUpInside];
        
        _editBtn;
    })];
    [_editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.contentView);
        make.left.mas_equalTo(_statusLabel.mas_right);
        make.width.mas_equalTo(kRealwidth(65));
    }];
    
}

- (void)edit:(UIButton *)button {
    if (self.editShop) {
        self.editShop();
    }
}

- (void)setNameModel:(WHStationNameModel *)nameModel {
    _nameModel = nameModel;
    
    _nameLabel.text = NSStringFormat(@"  %@  ", nameModel.stationName);
    _moneyLabel.text = nameModel.saveMoney;
    
    if (nameModel.joinStatus == 0) { //  待合作
        _statusLabel.text = @"待合作";
        [_editBtn setTitle:@"" forState:UIControlStateNormal];
    } else if (nameModel.joinStatus == 1) { //  已合作
        _statusLabel.text = @"通过";
        [_editBtn setTitle:@"修改" forState:UIControlStateNormal];
    } else if (nameModel.joinStatus == 2) { // 拒绝合作
        _statusLabel.text = @"拒绝";
        [_editBtn setTitle:@"申请" forState:UIControlStateNormal];
    }
}

@end
